package com.tiantianyuegou.pay;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;

import com.tiantianyuegou.enums.PayType;
import com.tiantianyuegou.model.PayOrderInfo;


/**
 * 账户余额支付
 */
public class AccountPay extends AbstractPay {

    private int orderType;
    OnMyPayListner listener;
    public AccountPay(int orderType) {
        this.orderType = orderType;
    }

    @Override
    public void pay(Activity activity, PayOrderInfo orderInfo, OnMyPayListner listener) {
        this.listener=listener;
        PayPasswordDialogFragment fragment = new PayPasswordDialogFragment();
        Bundle args = new Bundle();
        args.putString(PayPasswordDialogFragment.EXTRA_PRICE, orderInfo.getGoodsPrice());
        args.putString(PayPasswordDialogFragment.EXTRA_ORDERNO, orderInfo.getOrderNo());
        args.putInt(PayPasswordDialogFragment.EXTRA_ORDERTYPE, orderType);
        args.putString(PayPasswordDialogFragment.EXTRA_ORDERID, orderInfo.getOrderID());
        args.putString(PayPasswordDialogFragment.EXTRA_RECEIVE, orderInfo.getType());
        fragment.setArguments(args);
        fragment.show(((FragmentActivity) activity).getSupportFragmentManager(), "");
        //支付接口回调
        fragment.setPayResultListener(new PayPasswordDialogFragment.iPayResultListener() {
            @Override
            public void paySuccess() {
                callPaySuccess("success");
            }
        });
    }

    @Override
    protected void callPaySuccess(String result) {
        super.callPaySuccess(result);
        listener.onPaySuccessed(PayType.BLANACE, result);
    }


    @Override
    public boolean isInit() {
        return true;
    }


}
